package com.qingkai.onlineshop.presentation.dashboard

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.qingkai.onlineshop.R

/**
 *作者：created by 89270 on 2025/6/4 18:20
 *描述：
 */
@Composable
fun SearchBar(modifier: Modifier = Modifier) {
    var value by remember { mutableStateOf("") }
    Row(
        modifier = modifier,
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        OutlinedTextField(
            value = value,
            onValueChange = { value = it },
            shape = CircleShape,
            modifier = Modifier.weight(1f),
            colors = OutlinedTextFieldDefaults.colors(
                focusedBorderColor = MaterialTheme.colorScheme.surfaceContainer,
                unfocusedBorderColor = MaterialTheme.colorScheme.surfaceContainer,
                disabledBorderColor = MaterialTheme.colorScheme.surfaceContainer,
            ),
            leadingIcon = {
                Image(
                    painter = painterResource(R.drawable.search_icon),
                    contentDescription = "Search"
                )
            }, trailingIcon = {
                Image(
                    painter = painterResource(R.drawable.microphone),
                    contentDescription = "Microphone"
                )
            }
        )
        Image(painter = painterResource(R.drawable.settings_icon), contentDescription = "Settings")
    }
}

@Preview(showBackground = true)
@Composable
fun SearchBarPreview() {
    SearchBar()
}